package org.example.com.mapper;

import org.apache.ibatis.annotations.*;
import org.example.com.pojo.vo.ChatSession;

import java.util.List;

@Mapper
public interface ChatSessionMapper {
    
    // 创建新的聊天会话
    @Insert("INSERT INTO chat_sessions (id, user_id, title, status, created_at, updated_at) " +
            "VALUES (#{id}, #{userId}, #{title}, #{status}, NOW(), NOW())")
    void insert(ChatSession chatSession);
    
    // 根据会话ID查询会话
    @Select("SELECT id, user_id, title, status, created_at, updated_at " +
            "FROM chat_sessions WHERE id = #{id}")
    ChatSession findById(String id);
    
    // 根据用户ID查询所有会话
    @Select("SELECT id, user_id, title, status, created_at, updated_at " +
            "FROM chat_sessions WHERE user_id = #{userId} " +
            "ORDER BY updated_at DESC")
    List<ChatSession> findByUserId(Integer userId);
    
    // 更新会话标题
    @Update("UPDATE chat_sessions SET title = #{title}, updated_at = NOW() " +
            "WHERE id = #{id}")
    void updateTitle(@Param("id") String id, @Param("title") String title);
    
    // 更新会话状态
    @Update("UPDATE chat_sessions SET status = #{status}, updated_at = NOW() " +
            "WHERE id = #{id}")
    void updateStatus(@Param("id") String id, @Param("status") String status);
    
    // 删除会话
    @Delete("DELETE FROM chat_sessions WHERE id = #{id}")
    void deleteById(String id);
}
